package prototype

import "sync"

//Cloneable 是原型对象需要实现的接口
type Cloneable interface {
	Clone() Cloneable
}
type PrototypeManager struct {
	mux        sync.Mutex
	prototypes map[string]Cloneable
}

func NewPrototypeManager() *PrototypeManager {
	return &PrototypeManager{
		prototypes: make(map[string]Cloneable),
	}
}
func (p *PrototypeManager) Get(name string) Cloneable {
	p.mux.Lock()
	defer p.mux.Unlock()
	return p.prototypes[name]
}
func (p *PrototypeManager) Set(name string, c Cloneable) {
	p.mux.Lock()
	defer p.mux.Unlock()
	p.prototypes[name] = c
}
